<template>
  <div class="operationPageWrap">
    <div class="pageTableInner">
      <div class="infoSearchWrap">
        <div class="infoSearchOne">
          <el-row :gutter="20">
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">通知标题:</span>
                <span class="searchInputFont">
                    <el-input clearable size="mini" v-model="searchInfo.pushTitle" @change="searchRowsInfo(true)" auto-complete="off" placeholder="通知标题"></el-input>
                </span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="searchWrap">
                <span class="searchFont">发送日期:</span>
                <span class="searchInputFont">
                     <el-date-picker
                       style="width: 100%;"
                       v-model="value6"
                       type="daterange"
                       align="left"
                       @change="searchRowsInfo()"
                       placeholder="选择日期范围"
                       size="mini"
                       :picker-options="$store.state.pickerOptions2">
                      </el-date-picker>
                </span>
              </div>
            </el-col>
            <div style="float: right;margin-right: 10px;">
              <el-button type="primary" size="mini" @click="searchRowsInfo(true)">查询</el-button>
              <el-button type="primary" style="margin-left: 10px;" size="mini" @click="$refs.sendBtn.dialogOpen(multipleSelection)" v-if="$store.state.btnMenuIds.indexOf(234)>-1">短信通知

              </el-button>
            </div>

          </el-row>
        </div>
      </div>
      <div class="tableContainer">
        <div class="tableInner" ref="tableInner">
          <el-table
            ref="multipleTable"
            :data="rows"
            stripe
            :height="tableHeight"
            @selection-change="changeFun"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              label="发送时间"
              prop="createTime"
              show-overflow-tooltip
            >

            </el-table-column>
            <el-table-column
              label="标题"
              prop="pushTitle"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="通知内容"
              prop="pushContent"
            >
            </el-table-column>
            <el-table-column
              label="创建人员"
              prop="createName"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="通知人员"
              prop="userNames"
              show-overflow-tooltip>
            </el-table-column>
          </el-table>
        </div>
        <div style="text-align: left;margin-top: 15px;">
          <el-row :gutter="10">
            <el-col :span="13" :offset="9">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="searchInfo.page"
                :page-sizes="[10, 30, 50, 100,200]"
                :page-size="searchInfo.rows"
                layout="total, sizes, prev, pager, next, jumper"
                :total="count">
              </el-pagination>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
    <setBtn ref="setBtn" @searchRowsInfo="searchRowsInfo"></setBtn>
    <detailBtn ref="detailBtn"></detailBtn>
    <sendBtn ref="sendBtn" @searchRowsInfo="searchRowsInfo"></sendBtn>
  </div>
</template>

<script>
  import setBtn from "./setBtn.vue"
  import detailBtn from "./detailBtn.vue"
  import sendBtn from "./sendBtn.vue"
  export default {
    props: [],
    data(){
      return {
        rows: [],
        multipleSelection: [],
        options: [{label: "值班人员", value: 0}, {label: "应急人员", value: 1}],
        count: 0,
        tableHeight: 400,
        value6: "",
        searchInfo: {
          pushTitle: "",
          endTime: "",
          beginTime: "",
          page: 1,
          rows: 10,
        },
        streetData: [],
      }
    },
    components: {setBtn, detailBtn, sendBtn},
    created(){
      this.searchRowsInfo()

    },
    mounted(){
      setTimeout(() => {
        if (this.$store.state.userInfo.regionId) {this.changeDistrict(this.searchInfo.district)}
      }, 500)
      this.$nextTick(() => {
        //表格滚动
        this.tableHeight = document.querySelector(".operationPageWrap").clientHeight - 160
      })
    },

    methods: {
      //编辑
      handleEdit(row, key){
        let msg, url
        if (key) {   //启用
          msg = '确认启用人员 “' + row.userName + '” , 是否继续?'
          url = "enableSafeUser"
        } else {
          msg = '确认停用人员 “' + row.userName + '” , 是否继续?'
          url = "disableSafeUser"
        }
        this.$confirm(msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post(process.env.API_HOST + `/enterprise/` + url, {id: row.id})
            .then(response => {
              const result = response.data
              if (result.code === 200) {
                this.searchRowsInfo(true)
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
              }
            })

          //删除当前
        }).catch(() => {

        });
      },
      //获取街道
      changeDistrict(district){
        this.searchRowsInfo(true)
        if (!district) {
          this.searchInfo.street = ""
          this.streetData = []
          return
        }
        this.axios.post(process.env.API_HOST + '/common/selectRegion', {parentId: district})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.streetData = result.result
            }
          })
      },

      handleSizeChange(val) {
        this.searchInfo.rows = val
        this.searchRowsInfo()
      },
      handleCurrentChange(val) {
        this.searchInfo.page = val;
        this.searchRowsInfo()

      },
      //获取所有信息
      searchRowsInfo(val){
        val ?this.searchInfo.page = 1: ""
        if (this.value6&&this.value6[0] != null) {
          this.searchInfo.beginTime = this.dtime(this.value6[0]).format('YYYY-MM-DD 00:00:00')
          this.searchInfo.endTime = this.dtime(this.value6[1]).format('YYYY-MM-DD 23:59:59')
        } else {
          this.searchInfo.beginTime = ""
          this.searchInfo.endTime = ""
        }
        this.axios.post(process.env.API_HOST + `/enterprise/selectSafeMessageGrid`, this.searchInfo)
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.rows = result.rows
              this.count = result.total;
            }
          })
      },
    },
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .operationPageWrap
    page()

</style>
